﻿using Function;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UI.UserControl.UI
{
    public partial class MeregUpload : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 上传图片子文件夹
        /// </summary>
        public string SubPath { get; set; }

        /// <summary>
        /// 照片地址
        /// </summary>
        public string PhotoUrl { get { return GetPhotoUrl(); } }

        /// <summary>
        /// 是否选择了文件
        /// </summary>
        public bool HasFile { get { return FileUpload1.HasFile; } }

        private string GetPhotoUrl()
        {
            var photourl = "";
            var uploadpath = Method.AppSettings("UploadPath");
            var subpath = "";
            if (SubPath.IsNotEmpty())
                Method.AppSettings(SubPath);
            var phyuploadpath = uploadpath.ToPhysicalPath() + subpath;
            Method.CreateDirectory(phyuploadpath);
            var fullname = "";
            var extension = "";
            if (FileUpload1.HasFile)
            {
                extension = Path.GetExtension(FileUpload1.FileName);
                fullname = Method.UNIX() + extension;
                FileUpload1.SaveAs(phyuploadpath + fullname);
            }
            photourl = uploadpath.Replace("~", "") + subpath + fullname;
            return photourl;
        }
    }
}